using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace TTNgoaiNguSuPham
{
    public partial class frmTNTS : Form
    {
        public frmTNTS()
        {
            InitializeComponent();
        }

        private void numVongThi_ValueChanged(object sender, EventArgs e)
        {
            if (numVongThi.Value == 1)
                txtMaTS.Enabled = false;
            if (numVongThi.Value == 2)
                txtMaTS.Enabled = true;
        }

        private void btnfrmTK_Click(object sender, EventArgs e)
        {
            this.Hide();
            frmTimKiem_CapNhat frm = new frmTimKiem_CapNhat();
            frm.ShowDialog();
        }

        private void btnfrmBCTK_Click(object sender, EventArgs e)
        {
            this.Hide();
            frmBCTK frm = new frmBCTK();
            frm.ShowDialog();
        }

        public void LoadDTGV()
        {
            try
            {
                //dtgvThiSinhDKThi.Rows.Clear();
                DangKyThiQG_BUS dkbus = new DangKyThiQG_BUS();
                Double start = DateTime.Now.TimeOfDay.TotalMilliseconds;
                DataTable dt = dkbus.LayDSTSDangKy();
                Double finish = DateTime.Now.TimeOfDay.TotalMilliseconds;
                int delta = Convert.ToInt32(finish - start);
                lblThoiGianLoad.Text = delta.ToString();
                dtgvThiSinhDKThi.DataSource = dt;
            }
            catch (SqlException sql)
            {
                MessageBox.Show(sql.Message);
            }
        }

        private void frmTNTS_Load(object sender, EventArgs e)
        {
            try
            {
                KyThiQG_BUS ktBus = new KyThiQG_BUS();
                DataTable dt = ktBus.DSKyThi();
                cmbKyThi.DataSource = dt;
                cmbKyThi.DisplayMember = "MaKiThi_QG";

                LoaiNgonNgu_BUS nnBus = new LoaiNgonNgu_BUS();
                dt = new DataTable();
                dt = nnBus.DSNgonNgu();
                cmbNgonNgu.DataSource = dt;
                cmbNgonNgu.DisplayMember = "TenNN";
                cmbNgonNgu.ValueMember = "MaNN";

                LoaiChungChiQG_BUS ccBus = new LoaiChungChiQG_BUS();
                dt = new DataTable();
                dt = ccBus.DSChungChiQG();
                cmbChungChi.DataSource = dt;
                cmbChungChi.DisplayMember = "TenCC";
                cmbChungChi.ValueMember = "MaCC_QG";

                LoadDTGV();
            }
            catch (SqlException sql)
            {
                MessageBox.Show(sql.Message);
            }

        }

        private void btnTiepNhan_Click(object sender, EventArgs e)
        {
            try 
            {
                DangKyThiQG_BUS dkbus = new DangKyThiQG_BUS();
                ThiSinh_CMND_DTO ts_dto = new ThiSinh_CMND_DTO();

                ts_dto.HoTen = txtTenTS.Text;
                ts_dto.CMND = txtCMND.Text;
                ts_dto.DiaChi = txtDiaChi.Text;
                ts_dto.NgaySinh = dtpNgaySinh.Value;
                int MaTS = 0;
                int MaCC = int.Parse(cmbChungChi.SelectedValue.ToString());
                int MaNN = int.Parse(cmbNgonNgu.SelectedValue.ToString());
                int MaKT = int.Parse(cmbKyThi.Text);

                Double start = DateTime.Now.TimeOfDay.TotalMilliseconds;
                dkbus.ThemTSVong1(ts_dto, ref MaTS, MaCC, MaNN, MaKT);
                Double finish = DateTime.Now.TimeOfDay.TotalMilliseconds;
                int delta = Convert.ToInt32(finish - start);
                lblThoiGianThem.Text = delta.ToString();


                txtMaTS.Text = MaTS.ToString();

                MessageBox.Show("Tiep nhan thanh cong");

                LoadDTGV();
            }
            catch (SqlException sql)
            {
                MessageBox.Show(sql.Message);
            }
        }
    }
}